// 默认配置
export const getMainDomain = (url = location.host) => {
  const parts = url.split('.')
  if (parts.length >= 2) {
    url = parts.slice(-2).join('.')
  }
  return url
}
/**
 * 加载配置
 */
const loadAppConfig = () => {
  let domainUrl = getMainDomain()
  window.__config = {
    _BASE_API: window.VUE_APP_BASE_API || `http://${domainUrl}`,
  }
  for (const key in import.meta.env) {
    if (Object.hasOwnProperty.call(import.meta.env, key) && key.indexOf('VITE') > -1) {
      let tempKey = key.replace('VITE', '')
      window.__config[tempKey] = import.meta.env[key]
    }
  }
  window.__config = __config
  if (__config._USER_NODE_ENV == 'production') {
    Object.freeze(window.__config)
    Object.defineProperty(window, '__config', {
      configurable: false,
      writable: false,
      enumerable: false
    })
  }
}
// 执行加载配置
loadAppConfig()
